package myself.a013Map;

import java.util.*;

/**
 * @author 叶之越
 * Description
 * Date 2021/2/1
 * Time 14:58
 * Mail 739153436@qq.com
 */
public class BFS {
    // Breadth First Search 广度优先遍历
    public static void bfs(Node start) {
        if (start == null) {
            return;
        }
        Queue<Node> queue = new LinkedList<>();
        Set<Node> set = new HashSet<>();
        queue.add(start);
        set.add(start);
        while (!queue.isEmpty()) {
            System.out.println(start.value);
            Node cur = queue.poll();
            for (Node next : cur.nexts) {
                if (!set.contains(next)) {
                    queue.add(next);
                    set.add(next);
                }
            }
        }
    }
}
